import delimited "./ipeds/2016/hd2016.csv", stringcols(12 13 14) clear 

gen year=2016

keep ein sector iclevel control hloffer hdegofr1 deggrant c15basic c15ipgrd ccbasic carnegie

destring ein, generate(num_ein) force
drop if num_ein<0
drop if missing(num_ein)
drop num_ein

drop if deggrant==4

duplicates tag ein, gen(dup)
gen is_n_m3 = (carnegie!=-3)
bys ein: egen has_n_m3 = total(is_n_m3)
drop if has_n_m3>0 & is_n_m3==0 & dup>0
drop has_n_m3 is_n_m3 dup

duplicates drop
foreach num of numlist 15 16 21 22 31 {
duplicates tag ein, gen(dup)
gen is_`num' = (carnegie==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

duplicates tag ein, gen(dup)
gen is_n_m3 = (carnegie!=-3)
bys ein: egen has_n_m3 = total(is_n_m3)
drop if has_n_m3>0 & is_n_m3==0 & dup>0
drop has_n_m3 is_n_m3 dup

foreach num of numlist 15(1)23 {
duplicates tag ein, gen(dup)
gen is_`num' = (ccbasic==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

duplicates tag ein, gen(dup)
gen is_n_m3 = (ccbasic!=-3)
bys ein: egen has_n_m3 = total(is_n_m3)
drop if has_n_m3>0 & is_n_m3==0 & dup>0
drop has_n_m3 is_n_m3 dup

foreach num of numlist 15(1)23 27 {
duplicates tag ein, gen(dup)
gen is_`num' = (c15basic==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

duplicates tag ein, gen(dup)
gen is_n_m2 = (c15basic!=-2)
bys ein: egen has_n_m2 = total(is_n_m2)
drop if has_n_m2>0 & is_n_m2==0 & dup>0
drop has_n_m2 is_n_m2 dup

foreach num of numlist 14 15 17 18 16 13 12 4 5 {
duplicates tag ein, gen(dup)
gen is_`num' = (c15ipgrd==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

duplicates tag ein, gen(dup)
gen is_n_m2 = (c15ipgrd!=-2)
bys ein: egen has_n_m2 = total(is_n_m2)
drop if has_n_m2>0 & is_n_m2==0 & dup>0
drop has_n_m2 is_n_m2 dup

duplicates drop
foreach num of numlist 1 2 {
duplicates tag ein, gen(dup)
gen is_`num' = (deggrant==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

foreach num of numlist 9(1)2 {
duplicates tag ein, gen(dup)
gen is_`num' = (hloffer==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

duplicates tag ein, gen(dup)
gen is_0 = (sector==0)
bys ein: egen has_0 = total(is_0)
drop if has_0>0 & is_0==0 & dup>0
drop has_0 is_0 dup

foreach num of numlist 11(1)14 20 30 40 {
duplicates tag ein, gen(dup)
gen is_`num' = (hdegofr1==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

duplicates tag ein, gen(dup)
gen is_n_m3 = (hdegofr1!=-3)
bys ein: egen has_n_m3 = total(is_n_m3)
drop if has_n_m3>0 & is_n_m3==0 & dup>0
drop has_n_m3 is_n_m3 dup

duplicates tag ein, gen(dup)
gen is_n_0 = (hdegofr1!=0)
bys ein: egen has_n_0 = total(is_n_0)
drop if has_n_0>0 & is_n_0==0 & dup>0
drop has_n_0 is_n_0 dup

duplicates tag ein, gen(dup)
gen is_n_3 = (control!=3)
bys ein: egen has_n_3 = total(is_n_3)
drop if has_n_3>0 & is_n_3==0 & dup>0
drop has_n_3 is_n_3 dup

foreach num of numlist 32 33 40 {
duplicates tag ein, gen(dup)
gen is_`num' = (carnegie==`num')
bys ein: egen has_`num' = total(is_`num')
drop if has_`num'>0 & is_`num'==0 & dup>0
drop has_`num' is_`num' dup
}

*Random
gen runiform = runiform()
sort ein carnegie runiform ccbasic c15basic c15ipgrd
duplicates drop ein, force
drop  runiform

label variable ein "Employer Identification Number"
label variable sector "Sector of institution"
label variable iclevel "Level of institution"
label variable control "Control of institution"
label variable hloffer "Highest level of offering"
label variable hdegofr1 "Highest degree offered"
label variable deggrant "Degree granting status"
label variable c15basic "Carnegie Classification 2015: Basic"
label variable c15ipgrd "Carnegie Classification 2015: Graduate Instructional Program"
label variable ccbasic  "Carnegie Classification 2005/2010: Basic"
label variable carnegie "Carnegie Classification 2000"

label define label_sector 0 "Central office or Administrative Unit" 
label define label_sector 1 "4-year public", add 
label define label_sector 2 "4-year private, not-for-profit", add 
label define label_sector 3 "4-year private, for-profit", add 
label define label_sector 4 "2-year public", add 
label define label_sector 5 "2-year private, not-for-profit", add 
label define label_sector 6 "2-year private, for-profit", add 
label define label_sector 7 "Less than 2-year public", add 
label define label_sector 8 "Less than 2-year private, not-for-profit", add 
label define label_sector 9 "Less than 2-year private, for-profit", add 
label define label_sector 99 "sector not known", add 
label values sector label_sector

label define label_iclevel -3 "{Not available}" 
label define label_iclevel 1 "Four or more years", add 
label define label_iclevel 2 "At least 2 but less than 4 years", add 
label define label_iclevel 3 "Less than 2 years (below associate)", add 
label values iclevel label_iclevel

label define label_control -3 "{Not available}" 
label define label_control 1 "Public", add 
label define label_control 2 "Private, not-for-profit", add 
label define label_control 3 "Private, for-profit", add 
label values control label_control

label define label_hloffer -2 "{Not applicable, first-professional only}" 
label define label_hloffer -3 "{Not available}", add 
label define label_hloffer 0 "Other", add 
label define label_hloffer 1 "Award of less than one academic year", add 
label define label_hloffer 2 "At least 1, but less than 2 academic yea", add 
label define label_hloffer 3 "Associates degree", add 
label define label_hloffer 4 "At least 2, but less than 4 academic yea", add 
label define label_hloffer 5 "Bachelors degree", add 
label define label_hloffer 6 "Postbaccalaureate certificate", add 
label define label_hloffer 7 "Masters degree", add 
label define label_hloffer 8 "Post-masters certificate", add 
label define label_hloffer 9 "Doctors degree", add 
label values hloffer label_hloffer

label define label_hdegofr1 11 "Doctor^s degree - research/scholarship and professional practice"
label define label_hdegofr1 12 "Doctor^s degree - research/scholarship",add
label define label_hdegofr1 13 "Doctor^s degree -  professional practice",add
label define label_hdegofr1 14 "Doctor^s degree - other",add
label define label_hdegofr1 20 "Master^s degree",add
label define label_hdegofr1 30 "Bachelor^s degree",add
label define label_hdegofr1 40 "Associate^s degree",add
label define label_hdegofr1 0 "Non-degree granting",add
label define label_hdegofr1 -3 "{Not available}",add
label values hdegofr1 label_hdegofr1

label define label_deggrant -3 "{Not available}" 
label define label_deggrant 1 "Degree-granting", add 
label define label_deggrant 2 "Nondegree-granting, primarily postsecond", add 
label define label_deggrant 3 "Not primarily postsecondary institutions", add 
label define label_deggrant 4 "Institution is not an educational entity", add 
label values deggrant label_deggrant

label define label_c15basic 1 "Associate^s Colleges: High Transfer-High Traditional"
label define label_c15basic 2 "Associate^s Colleges: High Transfer-Mixed Traditional/Nontraditional",add
label define label_c15basic 3 "Associate^s Colleges: High Transfer-High Nontraditional",add
label define label_c15basic 4 "Associate^s Colleges: Mixed Transfer/Career & Technical-High Traditional",add
label define label_c15basic 5 "Associate^s Colleges: Mixed Transfer/Career & Technical-Mixed Traditional/Nontraditional",add
label define label_c15basic 6 "Associate^s Colleges: Mixed Transfer/Career & Technical-High Nontraditional",add
label define label_c15basic 7 "Associate^s Colleges: High Career & Technical-High Traditional",add
label define label_c15basic 8 "Associate^s Colleges: High Career & Technical-Mixed Traditional/Nontraditional",add
label define label_c15basic 9 "Associate^s Colleges: High Career & Technical-High Nontraditional",add
label define label_c15basic 10 "Special Focus Two-Year: Health Professions",add
label define label_c15basic 11 "Special Focus Two-Year: Technical Professions",add
label define label_c15basic 12 "Special Focus Two-Year: Arts & Design",add
label define label_c15basic 13 "Special Focus Two-Year: Other Fields",add
label define label_c15basic 14 "Baccalaureate/Associate^s Colleges: Associate^s Dominant",add
label define label_c15basic 15 "Doctoral Universities: Highest Research Activity",add
label define label_c15basic 16 "Doctoral Universities: Higher Research Activity",add
label define label_c15basic 17 "Doctoral Universities: Moderate Research Activity",add
label define label_c15basic 18 "Master^s Colleges & Universities: Larger Programs",add
label define label_c15basic 19 "Master^s Colleges & Universities: Medium Programs",add
label define label_c15basic 20 "Master^s Colleges & Universities: Small Programs",add
label define label_c15basic 21 "Baccalaureate Colleges: Arts & Sciences Focus",add
label define label_c15basic 22 "Baccalaureate Colleges: Diverse Fields",add
label define label_c15basic 23 "Baccalaureate/Associate^s Colleges: Mixed Baccalaureate/Associate^s",add
label define label_c15basic 24 "Special Focus Four-Year: Faith-Related Institutions",add
label define label_c15basic 25 "Special Focus Four-Year: Medical Schools & Centers",add
label define label_c15basic 26 "Special Focus Four-Year: Other Health Professions Schools",add
label define label_c15basic 27 "Special Focus Four-Year: Engineering Schools",add
label define label_c15basic 28 "Special Focus Four-Year: Other Technology-Related Schools",add
label define label_c15basic 29 "Special Focus Four-Year: Business & Management Schools",add
label define label_c15basic 30 "Special Focus Four-Year: Arts, Music & Design Schools",add
label define label_c15basic 31 "Special Focus Four-Year: Law Schools",add
label define label_c15basic 32 "Special Focus Four-Year: Other Special Focus Institutions",add
label define label_c15basic 33 "Tribal Colleges",add
label define label_c15basic -2 "Not applicable, not in Carnegie universe (not accredited or nondegree-granting)",add
label values c15basic label_c15basic

label define label_c15ipgrd 1 "Postbaccalaureate: Single program-Education"
label define label_c15ipgrd 2 "Postbaccalaureate: Single program-Business",add
label define label_c15ipgrd 3 "Postbaccalaureate: Single program-Other",add
label define label_c15ipgrd 4 "Postbaccalaureate: Comprehensive programs",add
label define label_c15ipgrd 5 "Postbaccalaureate: Arts & sciences-dominant",add
label define label_c15ipgrd 6 "Postbaccalaureate: Education-dominant, with Arts & Sciences",add
label define label_c15ipgrd 7 "Postbaccalaureate: Business-dominant, with Arts & Sciences",add
label define label_c15ipgrd 8 "Postbaccalaureate: Other-dominant, with Arts & Sciences",add
label define label_c15ipgrd 9 "Postbaccalaureate: Education-dominant, with other professional programs",add
label define label_c15ipgrd 10 "Postbaccalaureate: Business-dominant, with other professional programs",add
label define label_c15ipgrd 11 "Postbaccalaureate: Other-dominant, with other professional programs",add
label define label_c15ipgrd 12 "Research Doctoral: Single program-Education",add
label define label_c15ipgrd 13 "Research Doctoral: Single program-Other",add
label define label_c15ipgrd 14 "Research Doctoral: Comprehensive programs, with medical/veterinary school",add
label define label_c15ipgrd 15 "Research Doctoral: Comprehensive programs, no medical/veterinary school",add
label define label_c15ipgrd 16 "Research Doctoral: Humanities/social sciences-dominant",add
label define label_c15ipgrd 17 "Research Doctoral: STEM-dominant",add
label define label_c15ipgrd 18 "Research Doctoral: Professional-dominant",add
label define label_c15ipgrd 0 "Not classified (Exclusively Undergraduate)",add
label define label_c15ipgrd -2 "Not applicable, not in Carnegie universe (not accredited or nondegree-granting)",add
label values c15ipgrd label_c15ipgrd


label define label_ccbasic 1 "Associate^s--Public Rural-serving Small"
label define label_ccbasic 2 "Associate^s--Public Rural-serving Medium",add
label define label_ccbasic 3 "Associate^s--Public Rural-serving Large",add
label define label_ccbasic 4 "Associate^s--Public Suburban-serving Single Campus",add
label define label_ccbasic 5 "Associate^s--Public Suburban-serving Multicampus",add
label define label_ccbasic 6 "Associate^s--Public Urban-serving Single Campus",add
label define label_ccbasic 7 "Associate^s--Public Urban-serving Multicampus",add
label define label_ccbasic 8 "Associate^s--Public Special Use",add
label define label_ccbasic 9 "Associate^s--Private Not-for-profit",add
label define label_ccbasic 10 "Associate^s--Private For-profit",add
label define label_ccbasic 11 "Associate^s--Public 2-year colleges under 4-year universities",add
label define label_ccbasic 12 "Associate^s--Public 4-year Primarily Associate^s",add
label define label_ccbasic 13 "Associate^s--Private Not-for-profit 4-year Primarily Associate^s",add
label define label_ccbasic 14 "Associate^s--Private For-profit 4-year Primarily Associate^s",add
label define label_ccbasic 15 "Research Universities (very high research activity)",add
label define label_ccbasic 16 "Research Universities (high research activity)",add
label define label_ccbasic 17 "Doctoral/Research Universities",add
label define label_ccbasic 18 "Master^s Colleges and Universities (larger programs)",add
label define label_ccbasic 19 "Master^s Colleges and Universities (medium programs)",add
label define label_ccbasic 20 "Master^s Colleges and Universities (smaller programs)",add
label define label_ccbasic 21 "Baccalaureate Colleges--Arts & Sciences",add
label define label_ccbasic 22 "Baccalaureate Colleges--Diverse Fields",add
label define label_ccbasic 23 "Baccalaureate/Associate^s Colleges",add
label define label_ccbasic 24 "Theological seminaries, Bible colleges, and other faith-related institutions",add
label define label_ccbasic 25 "Medical schools and medical centers",add
label define label_ccbasic 26 "Other health professions schools",add
label define label_ccbasic 27 "Schools of engineering",add
label define label_ccbasic 28 "Other technology-related schools",add
label define label_ccbasic 29 "Schools of business and management",add
label define label_ccbasic 30 "Schools of art, music, and design",add
label define label_ccbasic 31 "Schools of law",add
label define label_ccbasic 32 "Other special-focus institutions",add
label define label_ccbasic 33 "Tribal Colleges",add
label define label_ccbasic -3 "Not applicable, not in Carnegie universe (not accredited or nondegree-granting)",add
label values ccbasic label_ccbasic

label define label_carnegie 15 "Doctoral/Research Universities--Extensive"
label define label_carnegie 16 "Doctoral/Research Universities--Intensive",add
label define label_carnegie 21 "Masters Colleges and Universities I",add
label define label_carnegie 22 "Masters Colleges and Universities II",add
label define label_carnegie 31 "Baccalaureate Colleges--Liberal Arts",add
label define label_carnegie 32 "Baccalaureate Colleges--General",add
label define label_carnegie 33 "Baccalaureate/Associates Colleges",add
label define label_carnegie 40 "Associates Colleges",add
label define label_carnegie 51 "Theological seminaries and other specialized faith-related institutions",add
label define label_carnegie 52 "Medical schools and medical centers",add
label define label_carnegie 53 "Other separate health profession schools",add
label define label_carnegie 54 "Schools of engineering and technology",add
label define label_carnegie 55 "Schools of business and management",add
label define label_carnegie 56 "Schools of art, music, and design",add
label define label_carnegie 57 "Schools of law",add
label define label_carnegie 58 "Teachers colleges",add
label define label_carnegie 59 "Other specialized institutions",add
label define label_carnegie 60 "Tribal colleges",add
label define label_carnegie -3 "{Item not available}",add
label values carnegie label_carnegie

save "./ipeds/2016/uni2016", replace

